<?php

class Berita extends CI_Model {

    function index() {
        $this->db->order_by('id', 'DESC');
        $q = $this->db->get('news');
        return $q;
    }

    function show($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('news');
        return $q;
    }

    function edit($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('news');
        return $q;
    }

    function create($title, $body, $date) {
        $data = array(
            'title' => $title,
            'body' => $body,
            'date' => $date,
        );
        $this->db->insert('news', $data);
        redirect('news/index');
    }

    function update($id, $title, $body, $date) {
        $data = array(
            'title' => $title,
            'body' => $body,
            'date' => $date,
        );
        $this->db->where('id', $id);
        $this->db->update('news', $data);
        redirect('news/index');
    }

    function delete($id) {
        $this->db->where('id', $id);
        $this->db->delete('news');
        redirect('news/index');
    }

    public function record_count() {
        return $this->db->count_all("news");
    }

    function fetch_costumer($limit, $start) {
        $this->db->order_by('id', 'DESC');
        $this->db->limit($limit, $start);
        $query = $this->db->get("news");
        return $query;
    }

}

?>
